#include "sprite.h"

namespace SkyID
{

//- Sprite --------------------------------------------------------------------
Sprite::Sprite(const Texture *texture, float x, float y, float w, float h) :
	mTexture(texture), mFlipX(false), mFlipY(false)
{
	setTextureRect(x, y, w, h);
}

Sprite::~Sprite()
{
	//
}

void Sprite::flip(bool flipX, bool flipY)
{
	if (mFlipX != flipX)
	{
		float t = mTextureRect.p1.x;
		mTextureRect.p1.x = mTextureRect.p2.x;
		mTextureRect.p2.x = t;
		mFlipX = flipX;
	}
	if (mFlipY != flipY)
	{
		float t = mTextureRect.p1.y;
		mTextureRect.p1.y = mTextureRect.p2.y;
		mTextureRect.p2.y = t;
		mFlipY = flipY;
	}
}

void Sprite::setTextureRect(float x, float y, float w, float h)
{
	mWidth = w;
	mHeight = h;
	mTextureRect.p1.x = x / mTexture->getWidth();
	mTextureRect.p1.y = y / mTexture->getHeight();
	mTextureRect.p2.x = (x+w) / mTexture->getWidth();
	mTextureRect.p2.y = (y+h) / mTexture->getHeight();
}

} // namespace SkyID
